<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :maskClosable="false"
    :keyboard="false"
    :forceRender="true"
    :style="modalStyle"
    @cancel="handleCancel"
    wrapClassName="ant-modal-cust-warp"
  >
    <template slot="footer">
      <!--此处为解决缓存问题-->
      <a-button v-if="financialType === '收预付款'" v-print="'#advanceInPrint'" ghost type="primary">打印</a-button>
      <a-button v-if="financialType === '转账'" v-print="'#giroPrint'" ghost type="primary">打印</a-button>
      <a-button v-if="financialType === '收入'" v-print="'#itemInPrint'" ghost type="primary">打印</a-button>
      <a-button v-if="financialType === '支出'" v-print="'#itemOutPrint'" ghost type="primary">打印</a-button>
      <a-button v-if="financialType === '收款'" v-print="'#moneyInPrint'" ghost type="primary">打印</a-button>
      <a-button v-if="financialType === '付款'" v-print="'#moneyOutPrint'" ghost type="primary">打印</a-button>
      <!--反审核-->
      <a-button v-if="checkFlag && isCanBackCheck && model.status === '1'" @click="handleBackCheck()">反审核</a-button>
      <a-button key="back" @click="handleCancel">取消</a-button>
    </template>
    <a-form :form="form">
      <!--收预付款-->
      <template v-if="financialType === '收预付款'">
        <section ref="print" id="advanceInPrint">
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="付款会员">
                <a-input v-decorator="['id']" hidden />
                {{ model.organName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="财务人员">
                {{ model.handsPersonName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据日期">
                {{ model.billTimeStr }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据编号">
                {{ model.billNo }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :pagination="false"
            :loading="loading"
            :columns="advanceInColumns"
            :dataSource="dataSource"
          >
          </a-table>
          <a-row class="form-row" :gutter="24">
            <a-col :lg="24" :md="24" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }"
                label=""
                style="padding: 20px 10px"
              >
                {{ model.remark }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="合计金额">
                {{ model.totalPrice }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收款金额">
                {{ model.changeAmount }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收款方式">
                {{ model.payType }}
              </a-form-item>
            </a-col>
            <a-col :span="6"></a-col>
            <a-col :span="6"></a-col>
          </a-row>
        </section>
      </template>
      <!--转账-->
      <template v-if="financialType === '转账'">
        <section ref="print" id="giroPrint">
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="财务人员">
                <a-input v-decorator="['id']" hidden />
                {{ model.handsPersonName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据日期">
                {{ model.billTimeStr }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据编号">
                {{ model.billNo }}
              </a-form-item>
            </a-col>
            <a-col :span="6"></a-col>
          </a-row>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :pagination="false"
            :loading="loading"
            :columns="giroColumns"
            :dataSource="dataSource"
          >
          </a-table>
          <a-row class="form-row" :gutter="24">
            <a-col :lg="24" :md="24" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }"
                label=""
                style="padding: 20px 10px"
              >
                {{ model.remark }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="付款账户">
                {{ model.accountName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="实付金额">
                {{ model.changeAmount }}
              </a-form-item>
            </a-col>
            <a-col :span="6"></a-col>
            <a-col :span="6"></a-col>
          </a-row>
        </section>
      </template>
      <!--收入-->
      <template v-if="financialType === '收入'">
        <section ref="print" id="itemInPrint">
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="往来单位">
                <a-input v-decorator="['id']" hidden />
                {{ model.organName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="财务人员">
                {{ model.handsPersonName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据日期">
                {{ model.billTimeStr }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据编号">
                {{ model.billNo }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :pagination="false"
            :loading="loading"
            :columns="itemInColumns"
            :dataSource="dataSource"
          >
          </a-table>
          <a-row class="form-row" :gutter="24">
            <a-col :lg="24" :md="24" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }"
                label=""
                style="padding: 20px 10px"
              >
                {{ model.remark }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收入账户">
                {{ model.accountName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收入金额">
                {{ model.changeAmount }}
              </a-form-item>
            </a-col>
            <a-col :span="6"></a-col>
            <a-col :span="6"></a-col>
          </a-row>
        </section>
      </template>
      <!--支出-->
      <template v-if="financialType === '支出'">
        <section ref="print" id="itemOutPrint">
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="往来单位">
                <a-input v-decorator="['id']" hidden />
                {{ model.organName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="财务人员">
                {{ model.handsPersonName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据日期">
                {{ model.billTimeStr }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据编号">
                {{ model.billNo }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :pagination="false"
            :loading="loading"
            :columns="itemOutColumns"
            :dataSource="dataSource"
          >
          </a-table>
          <a-row class="form-row" :gutter="24">
            <a-col :lg="24" :md="24" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }"
                label=""
                style="padding: 20px 10px"
              >
                {{ model.remark }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="支出账户">
                {{ model.accountName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="支出金额">
                {{ model.changeAmount }}
              </a-form-item>
            </a-col>
            <a-col :span="6"></a-col>
            <a-col :span="6"></a-col>
          </a-row>
        </section>
      </template>
      <!--收款-->
      <template v-if="financialType === '收款'">
        <section ref="print" id="moneyInPrint">
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="客户">
                <a-input v-decorator="['id']" hidden />
                {{ model.organName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="财务人员">
                {{ model.handsPersonName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据日期">
                {{ model.billTimeStr }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据编号">
                {{ model.billNo }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :pagination="false"
            :loading="loading"
            :columns="moneyInColumns"
            :dataSource="dataSource"
          >
            <template slot="customBillNumber" slot-scope="value">
              <!-- <span>{{ record }}</span> -->
              <a @click="myHandleDetail(value)">{{ value }}</a>
            </template>
          </a-table>

          <a-row class="form-row" :gutter="24">
            <a-col :lg="24" :md="24" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }"
                label=""
                style="padding: 20px 10px"
              >
                {{ model.remark }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收款账户">
                {{ model.accountName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="合计收款">
                {{ model.totalPrice }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="优惠金额">
                {{ model.discountMoney }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="实际收款">
                {{ model.changeAmount }}
              </a-form-item>
            </a-col>
          </a-row>
        </section>
      </template>
      <!--付款-->
      <template v-if="financialType === '付款'">
        <section ref="print" id="moneyOutPrint">
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="供应商">
                <a-input v-decorator="['id']" hidden />
                {{ model.organName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="财务人员">
                {{ model.handsPersonName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据日期">
                {{ model.billTimeStr }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据编号">
                {{ model.billNo }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :pagination="false"
            :loading="loading"
            :columns="moneyOutColumns"
            :dataSource="dataSource"
          >
          </a-table>
          <a-row class="form-row" :gutter="24">
            <a-col :lg="24" :md="24" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }"
                label=""
                style="padding: 20px 10px"
              >
                {{ model.remark }}
              </a-form-item>
            </a-col>
          </a-row>
          <a-row class="form-row" :gutter="24">
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="付款账户">
                {{ model.accountName }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="合计付款">
                {{ model.totalPrice }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="优惠金额">
                {{ model.discountMoney }}
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="实际付款">
                {{ model.changeAmount }}
              </a-form-item>
            </a-col>
          </a-row>
        </section>
      </template>

      <!--销售订单-->
      <a-modal
        title="销售订单"
        :width="1600"
        :visible="visibleOrder"
        :maskStyle="{ top: '93px', left: '154px' }"
        wrapClassName="ant-modal-cust-warp depot-mask"
        :mask="true"
        :maskClosable="false"
        cancelText="关闭"
        @ok="visibleOrder = false"
        @cancel="visibleOrder = false"
        style="top: 20px; height: 95%"
      >
        <template>
          <section ref="print" id="saleOrderPrint">
            <a-row class="form-row" :gutter="24">
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="客户">
                  <a-input v-decorator="['id']" hidden />
                  {{ modelOrder.organName }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据日期">
                  {{ modelOrder.operTimeStr }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="单据编号">
                  {{ modelOrder.number }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="销售人员">
                  {{ modelOrder.salesManStr }}
                </a-form-item>
              </a-col>
            </a-row>
            <div :style="tableWidth">
              <a-table
                ref="table"
                size="middle"
                bordered
                rowKey="id"
                :pagination="false"
                :loading="loadingOrder"
                :columns="saleOrderColumns"
                :dataSource="dataSourceOrder"
              >
                <template slot="customBarCode" slot-scope="text, record">
                  <div :style="record.imgName ? 'float:left;line-height:30px' : 'float:left;'">
                    {{ record.barCode }}
                  </div>
                  <a-popover placement="right" trigger="click">
                    <template slot="content"
                      ><img :src="getImgUrl(record.imgName, record.imgLarge)" width="500px"
                    /></template>
                    <div class="item-info" v-if="record.imgName">
                      <img
                        v-if="record.imgName"
                        :src="getImgUrl(record.imgName, record.imgSmall)"
                        class="item-img"
                        title="查看大图"
                      />
                    </div>
                  </a-popover>
                </template>

                <template slot="customRenderXsthFlag" slot-scope="text, record">
                  <a-tag v-if="record.xsthFlag == '0'" color="green">正常</a-tag>
                  <a-tag v-if="record.xsthFlag == '1'" color="red">存在退货</a-tag>
                  <a-tag v-if="record.xsthFlag == '2'" color="blue">完全退货</a-tag>
                </template>
              </a-table>
            </div>
            <a-row class="form-row" :gutter="24">
              <a-col :lg="24" :md="24" :sm="24">
                <a-form-item
                  :labelCol="labelCol"
                  :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }"
                  label=""
                  style="padding: 20px 10px"
                >
                  {{ modelOrder.remark }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row class="form-row" :gutter="24">
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="优惠率">
                  {{ modelOrder.discount }}%
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="付款优惠">
                  {{ modelOrder.discountMoney }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  :labelCol="{ xs: { span: 24 }, sm: { span: 6 } }"
                  :wrapperCol="wrapperCol"
                  label="优惠后金额"
                >
                  {{ modelOrder.discountLastMoney }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item :labelCol="{ xs: { span: 24 }, sm: { span: 6 } }" :wrapperCol="wrapperCol" label="收件人">
                  {{ modelOrder.addressee }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row class="form-row" :gutter="24">
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="结算账户">
                  {{ modelOrder.accountName }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="收取订金">
                  {{ modelOrder.changeAmount }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  :labelCol="{ xs: { span: 24 }, sm: { span: 6 } }"
                  :wrapperCol="wrapperCol"
                  label="联系电话"
                >
                  {{ modelOrder.contact }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  :labelCol="{ xs: { span: 24 }, sm: { span: 6 } }"
                  :wrapperCol="wrapperCol"
                  label="收件地址"
                >
                  {{ modelOrder.address }}
                </a-form-item>
              </a-col>
            </a-row>
            <a-row class="form-row" :gutter="24">
              <a-col :span="6">
                <a-form-item :labelCol="{ xs: { span: 24 }, sm: { span: 6 } }" :wrapperCol="wrapperCol" label="运费">
                  {{ modelOrder.freight }}
                </a-form-item>
              </a-col>
              <a-col :span="6">
                <a-form-item
                  :labelCol="{ xs: { span: 24 }, sm: { span: 6 } }"
                  :wrapperCol="wrapperCol"
                  label="销售员手机号"
                >
                  {{ modelOrder.saleManPhone }}
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-col v-for="(itemObj, indexObj) in modelOrder.logisticsInformation" :key="indexObj" :span="12">
                  <a-form-item
                    :labelCol="{ xs: { span: 24 }, sm: { span: 6 } }"
                    :wrapperCol="wrapperCol"
                    label="快递信息："
                  >
                    <a-popover v-for="(item, index) in itemObj.urls" :key="index" placement="right" trigger="click">
                      <template slot="content"><img :src="getImgUrl(item, item)" width="500px" /></template>
                      <div class="item-info" v-if="item">
                        <img v-if="item" :src="getImgUrl(item, item)" class="item-img" title="查看大图" />
                      </div>
                    </a-popover>
                  </a-form-item>
                </a-col>
              </a-col>
            </a-row>
          </section>
        </template>
      </a-modal>

      <template v-if="fileList && fileList.length > 0">
        <a-row class="form-row" :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="{ xs: { span: 24 }, sm: { span: 3 } }"
              :wrapperCol="{ xs: { span: 24 }, sm: { span: 21 } }"
              label="附件"
            >
              <j-upload v-model="fileList" bizPath="bill" :disabled="true" :buttonVisible="false"></j-upload>
            </a-form-item>
          </a-col>
          <a-col :span="12"></a-col>
        </a-row>
      </template>
    </a-form>
  </j-modal>
</template>
<script>
import pick from 'lodash.pick'
import { getAction, postAction, getFileAccessHttpUrl } from '@/api/manage'
import { findFinancialDetailByNumber, getCurrentSystemConfig, findBillDetailByNumber } from '@/api/api'
import { getMpListShort, getCheckFlag, openDownloadDialog, sheet2blob } from '@/utils/util'
import JUpload from '@/components/jeecg/JUpload'
import Vue from 'vue'
export default {
  name: 'FinancialDetail',
  components: {
    JUpload,
  },
  data() {
    return {
      title: '详情',
      width: '1600px',
      visible: false,
      modalStyle: '',
      model: {},
      isCanBackCheck: true,
      financialType: '',
      fileList: [],
      /* 原始反审核是否开启 */
      checkFlag: true,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      form: this.$form.createForm(this),
      loading: false,
      dataSource: [],
      url: {
        detailList: '/accountItem/getDetailList',
        batchSetStatusUrl: '/accountHead/batchSetStatus',
      },
      advanceInColumns: [
        { title: '账户名称', dataIndex: 'accountName', width: '30%' },
        { title: '金额', dataIndex: 'eachAmount', width: '30%' },
        { title: '备注', dataIndex: 'remark', width: '30%' },
      ],
      giroColumns: [
        { title: '账户名称', dataIndex: 'accountName', width: '30%' },
        { title: '金额', dataIndex: 'eachAmount', width: '30%' },
        { title: '备注', dataIndex: 'remark', width: '30%' },
      ],
      itemInColumns: [
        { title: '收入项目', dataIndex: 'inOutItemName', width: '30%' },
        { title: '金额', dataIndex: 'eachAmount', width: '30%' },
        { title: '备注', dataIndex: 'remark', width: '30%' },
      ],
      itemOutColumns: [
        { title: '支出项目', dataIndex: 'inOutItemName', width: '30%' },
        { title: '金额', dataIndex: 'eachAmount', width: '30%' },
        { title: '备注', dataIndex: 'remark', width: '30%' },
      ],
      moneyInColumns: [
        {
          title: '销售单据编号',
          dataIndex: 'billNumber',
          width: '20%',

          scopedSlots: { customRender: 'customBillNumber' },
        },
        { title: '应收欠款', dataIndex: 'needDebt', width: '10%' },
        { title: '已收欠款', dataIndex: 'finishDebt', width: '10%' },
        { title: '本次收款', dataIndex: 'eachAmount', width: '10%' },
        { title: '备注', dataIndex: 'remark', width: '20%' },
      ],
      moneyOutColumns: [
        {
          title: '采购单据编号',
          dataIndex: 'billNumber',
          width: '20%',
        },
        { title: '应付欠款', dataIndex: 'needDebt', width: '10%' },
        { title: '已付欠款', dataIndex: 'finishDebt', width: '10%' },
        { title: '本次付款', dataIndex: 'eachAmount', width: '10%' },
        { title: '备注', dataIndex: 'remark', width: '20%' },
      ],
      // 销售订单
      modelOrder: {},
      visibleOrder: false,
      loadingOrder: false,
      dataSourceOrder: [],
      tableWidth: {
        width: '1500px',
      },
      saleOrderColumns: [
        { title: '条码', dataIndex: 'barCode', scopedSlots: { customRender: 'customBarCode' } },
        { title: '名称', dataIndex: 'name' },
        { title: '规格', dataIndex: 'standard' },
        { title: '型号', dataIndex: 'model' },
        { title: '颜色', dataIndex: 'color' },
        { title: '扩展信息', dataIndex: 'materialOther' },
        { title: '库存', dataIndex: 'stock' },
        { title: '单位', dataIndex: 'unit' },
        { title: '多属性', dataIndex: 'sku' },
        { title: '数量', dataIndex: 'operNumber' },
        { title: '已出库', dataIndex: 'finishNumber' },
        { title: '单价', dataIndex: 'unitPrice' },
        { title: '金额', dataIndex: 'allPrice' },
        { title: '退货状态', dataIndex: 'xsthFlag', scopedSlots: { customRender: 'customRenderXsthFlag' } },
        // { title: '税率(%)', dataIndex: 'taxRate' },
        // { title: '税额', dataIndex: 'taxMoney' },
        // { title: '价税合计', dataIndex: 'taxLastMoney' },
        { title: '备注', dataIndex: 'remark' },
      ],
    }
  },
  created() {
    let realScreenWidth = window.screen.width
    this.width = realScreenWidth < 1500 ? '1200px' : '1550px'
  },
  methods: {
    show(record, type, prefixNo) {
      //查询单条财务信息
      findFinancialDetailByNumber({ billNo: record.billNo }).then((res) => {
        if (res && res.code === 200) {
          let item = res.data
          this.financialType = type
          this.prefixNo = prefixNo
          //附件下载
          this.fileList = item.fileName
          this.visible = true
          this.modalStyle = 'top:20px;height: 95%;'
          this.model = Object.assign({}, item)
          this.$nextTick(() => {
            this.form.setFieldsValue(pick(this.model, 'id'))
          })
          let params = {
            headerId: this.model.id,
          }
          let url = this.readOnly ? this.url.detailList : this.url.detailList
          this.requestSubTableData(url, params)
          this.getSystemConfig()
        }
      })
    },

    showSaleOrderColumns(record, type, prefixNo) {
      //查询单条单据信息
      findBillDetailByNumber({ number: record.number }).then((res) => {
        if (res && res.code === 200) {
          if (res.data.logisticsInformation) {
            res.data.logisticsInformation = JSON.parse(res.data.logisticsInformation)

            if (Array.isArray(res.data.logisticsInformation)) {
              let newArray = []
              res.data.logisticsInformation.map((value) => {
                let obj = JSON.parse(value)
                obj['urls'] = obj.imgName ? obj.imgName.split(',') : []
                newArray.push(obj)
              })
              res.data.logisticsInformation = newArray
            } else {
              res.data.logisticsInformation['urls'] = res.data.logisticsInformation.imgName
                ? res.data.logisticsInformation.imgName.split(',')
                : []
            }
          } else {
            res.data.logisticsInformation = {
              urls: [],
            }
          }

          let item = res.data
          this.billType = type
          this.prefixNo = prefixNo
          //附件下载
          this.fileList = item.fileName
          this.visible = true
          this.modalStyle = 'top:20px;height: 95%;'
          this.modelOrder = Object.assign({}, item)
          this.visibleOrder = true
          if (this.modelOrder.backAmount) {
            this.modelOrder.getAmount = (this.modelOrder.changeAmount + this.modelOrder.backAmount).toFixed(2)
          } else {
            this.modelOrder.getAmount = this.modelOrder.changeAmount
          }
          this.modelOrder.debt = (
            this.modelOrder.discountLastMoney +
            this.modelOrder.otherMoney -
            (this.modelOrder.deposit + this.modelOrder.changeAmount)
          ).toFixed(2)
          this.$nextTick(() => {
            this.form.setFieldsValue(pick(this.modelOrder, 'id'))
          })
          let showType = 'basic'
          if (item.status === '3') {
            showType = 'basic'
          } else if (item.purchaseStatus === '3') {
            showType = 'purchase'
          }
          let params = {
            headerId: this.modelOrder.id,
            mpList: getMpListShort(Vue.ls.get('materialPropertyList')), //扩展属性
            linkType: showType,
            isReadOnly: '1',
          }
          let url = 'depotItem/getDetailList'
          this.requestSubTableDataOrder(item, type, url, params)
          // this.initPlatform()
          // this.getSystemConfig()
          // this.getBillListByLinkNumber(this.model.number)
          // this.getFinancialBillNoByBillId(this.model.id)
        }
      })
    },
    requestSubTableDataOrder(record, type, url, params, success) {
      this.loadingOrder = true
      getAction(url, params)
        .then((res) => {
          if (res && res.code === 200) {
            this.dataSourceOrder = res.data.rows
            // this.initSetting(record, type, this.dataSource)
            typeof success === 'function' ? success(res) : ''
          }
        })
        .finally(() => {
          this.loadingOrder = false
        })
    },
    getImgUrl(imgName, type) {
      if (imgName && imgName.split(',')) {
        type = type ? type + '/' : ''
        return getFileAccessHttpUrl('systemConfig/static/' + imgName.split(',')[0])
      } else {
        return ''
      }
    },

    requestSubTableData(url, params, success) {
      this.loading = true
      getAction(url, params)
        .then((res) => {
          if (res && res.code === 200) {
            this.dataSource = res.data.rows
            typeof success === 'function' ? success(res) : ''
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    getSystemConfig() {
      getCurrentSystemConfig().then((res) => {
        if (res.code === 200 && res.data) {
          let multiBillType = res.data.multiBillType
          let multiLevelApprovalFlag = res.data.multiLevelApprovalFlag
          this.checkFlag = getCheckFlag(multiBillType, multiLevelApprovalFlag, this.prefixNo)
        }
      })
    },
    handleBackCheck() {
      let that = this
      this.$confirm({
        title: '确认操作',
        content: '是否对该单据进行反审核?',
        onOk: function () {
          that.loading = true
          postAction(that.url.batchSetStatusUrl, { status: '0', ids: that.model.id })
            .then((res) => {
              if (res.code === 200) {
                that.$emit('ok')
                that.loading = false
                that.close()
              } else {
                that.$message.warning(res.data.message)
                that.loading = false
              }
            })
            .finally(() => {})
        },
      })
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.modalStyle = ''
    },

    myHandleDetail(billNumber) {
      this.dataSourceOrder = []
      findBillDetailByNumber({ number: billNumber }).then((res) => {
        if (res && res.code === 200) {
          let type = res.data.type === '其它' ? '' : res.data.type
          this.showSaleOrderColumns(res.data, res.data.subType + type)
        }
      })
    },
  },
}
</script>

<style scoped>
.item-info {
  float: left;
  width: 30px;
  height: 30px;
  margin-left: 8px;
}
.item-img {
  cursor: pointer;
  position: static;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>